<template>
	<div class="system-role-container layout-padding">
		<div class="system-role-padding layout-padding-auto">
			<el-card shadow="hover" class="pageQueryBoxArea mb10">
				<el-form :model="state.param" :inline="true">
					<el-form-item label="短信类型：">
						<el-select v-model="state.param.type" placeholder="请选择门店属性" class="w100">
							<el-option v-for="item in state.query.smsType" :key="item.value"
								:label="item.label" :value="item.value" />
						</el-select>
					</el-form-item>
					<el-form-item label="日期选择：">
						<el-date-picker v-model="state.param.dateTime" type="daterange" unlink-panels :shortcuts="shortcuts"
							format="YYYY/MM/DD" value-format="YYYY-MM-DD" range-separator="-" :disabled-date="disabledDate"
							start-placeholder="开始日期" end-placeholder="结束日期" />
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="search()">
							<el-icon>
								<ele-Search />
							</el-icon> 搜 索
						</el-button>
					</el-form-item>
				</el-form>
			</el-card>
			<el-card shadow="hover" style="display: flex;flex-direction: column;flex: 1;height: inherit;">
				<section style="display: flex;flex-direction: column; flex: 1;height: inherit;">
					<el-table :data="state.tableData" style="width: 100%"> 
						<el-table-column prop="id" label="ID" show-overflow-tooltip width="90"></el-table-column>
						<el-table-column label="短信内容" show-overflow-tooltip>
							<template #default="scope">
								<span>{{ scope.row.content }}</span>
							</template>
						</el-table-column>
						<el-table-column label="签名" show-overflow-tooltip width="140">
							<template #default="scope">
								<span>{{ scope.row.sign }}</span>
							</template>
						</el-table-column>
						<el-table-column label="发送时间" show-overflow-tooltip width="180">
							<template #default="scope">
								<span>{{ scope.row.sendTime}}</span>
							</template>
						</el-table-column>
					</el-table>
					<el-row justify="end">
						<el-col :span="24" class="flex-end-center">
							<el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15"
								:pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="state.param.pageNum" background
								v-model:page-size="state.param.pageSize" layout="total, sizes, prev, pager, next, jumper"
								:total="state.total">
							</el-pagination>
						</el-col>
					</el-row>
				</section>
			</el-card>
		</div>
	</div>
</template>

<script setup lang="ts" name="saleIndex">
import { reactive, onMounted, ref, defineAsyncComponent } from 'vue';
import { historyList } from '/@/api/notice';
import { ElMessageBox, ElMessage, TabsPaneContext } from 'element-plus';

// 引入组件
// 定义变量内容

const goodTableRef = ref();
const state = reactive({
	param: {
		type: 1,
		dateTime: [],
		pageNum: 1,
		pageSize: 10,
	},
	loading: false,
	total: 0,
	tableData: [{}],
	query: {
		smsType: [
			{ value: 0, label: '通知短信' },
			{ value: 1, label: '群发短信' }
		]
	}
});

const shortcuts = [
	{
		text: '本月',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.setDate(1))
		return [start, end]
		},
	},
	{
		text: '近一个月',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
		return [start, end]
		},
	},
	{
		text: '近三个月',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
		return [start, end]
		},
	},
	{
		text: '近半年',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 180)
		return [start, end]
		},
	},
	{
		text: '近一年',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 365)
		return [start, end]
		},
	},
]

const disabledDate = (time: Date) => {
  return time.getTime() > Date.now()
}

// 搜索
const search = () => {
	state.param.pageNum = 1;
	getList();
}

// 获取商品列表
const getList = async () => {
	state.loading = true;//不用传参， 请求得入参在上面都定义了 param这里吗？
	let params = {
		pageNum: state.param.pageNum,
		pageSize: state.param.pageSize,
		type: state.param.type,
	}
	const { results } = await historyList(params);
	state.loading = false;
	state.tableData = results.page.records;
	state.total = results.page.total;
}

// 分页点击 条数
const onHandleSizeChange = (val: number) => {
	state.param.pageSize = val;
	getList();
};

// 分页点击
const onHandleCurrentChange = (val: number) => {
	state.param.pageNum = val;
	getList();
};

onMounted(() => {
	// 获取
	getList();
})
</script>
<style scoped lang="scss">
@import '../../../theme/mixins/index.scss';
:deep(.el-card__body){
	display: flex;
	flex-direction: column;
	flex: 1;
	height: inherit;
	.el-table{
		flex: 1;
		.el-table__inner-wrapper::before{
			background: none !important;
		}
	}
}
</style>